<?php

namespace app\admin\controller\projects\video;

use app\Base;
use app\service\admin\projects\video\ClassifyService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
use think\response\View;

/**
 * 分类
 * User : Du
 * Date : 2023/2/9
 * Time : 14:22
 * Class Classify
 * @package projects\controller\admin\video
 */
class Classify extends Base
{

    /**
     * 首页
     * User : Du
     * Date : 2023/2/9
     * Time : 14:23
     * @return View
     */
    public function index(): View
    {
        return view('projects/video/classify');
    }

    /**
     * 类型列表
     *
     * User : Du
     * Date : 2022/3/31
     * Time : 11:21
     * @param ClassifyService $service
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getList(ClassifyService $service): Json
    {
        $res = $service::getList($this->params);
        $this->res['data'] = $res['data'];
        $this->res['count'] = $res['count'];
        return $this->returnData();
    }

    /**
     * 添加
     * User : Du
     * Date : 2023/2/9
     * Time : 16:25
     * @param ClassifyService $service
     * @return Json
     */
    public function add(ClassifyService $service): Json
    {
        $res = $service::addData($this->params);
        if (!$res) {
            return $this->returnData('addFail');
        }
        return $this->returnData();
    }

    public function update()
    {
    }

    public function delete()
    {
    }
}
